package com.dmall.service.impl;

import com.dmall.datasource.annotation.DataSource;
import com.dmall.mapper.UserMapper;
import com.dmall.pojo.User;
import com.dmall.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 用户管理Service实现类
 * @author xiao1.wang
 * @date 2019-06-25 13:28:50
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    @DataSource("master")
    public List<User> masterList() {
        return userMapper.list();
    }

    @Override
    @DataSource("slave")
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public void saveUser(User user) {
        userMapper.insertUser(user);
    }

    @Override
    @DataSource("slave")
    public List<User> slaveList() {
        return userMapper.list();
    }
}
